package cn.echoedu.specifics;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.echoedu.daoconstants.TableName;
import cn.echoedu.entity.User;
import cn.echoedu.util.L;

public class SpecUser extends BaseSpec{
	private final String T="SpecUser----->";
	@Override
	public <T> PreparedStatement getPreparedInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		L.gpi(T);
		User user=(User)currentPojo;
		String sql="insert into "+tableName+" values(?,?)";
		PreparedStatement preparedstatement=con.prepareStatement(sql);
		preparedstatement.setString(1,user.getUsernumber());
		 preparedstatement.setInt(2,user.getRole());
		return preparedstatement;
	}

	@Override
	public <T> PreparedStatement getPreparedInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		L.gpir(T);
		User user=(User)currentPojo;
		String sql="insert into "+tableName+" values(?,?)";
		PreparedStatement preparedstatement=con.prepareStatement(sql);
		preparedstatement.setString(1,user.getUsernumber());
		 preparedstatement.setInt(2,user.getRole());
		return preparedstatement;
	}

	@Override
	public Object getPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		User user=new User();
		 
		user.setUsernumber(rs.getString(1));
		user.setRole(rs.getInt(2));
		return user;
	}
    
	@Override
	public <T> PreparedStatement getPreparedUpdate(Connection con,
			TableName tableName, T oldPojo, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		User newuser=(User)currentPojo;
		User olduser=(User)oldPojo;
		String sql="update user set usernumber=?,role=? where userid=?";
		PreparedStatement preparedstatement=con.prepareStatement(sql);
		 
		preparedstatement.setInt(1,newuser.getRole());
		preparedstatement.setString(2,olduser.getUsernumber());
		 return preparedstatement;
	}

	@Override
	public Object getLeftJoinPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getPojoBySql(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> String getPreparedInsertGetPrimaryKeySql(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
